package com.example.tic_tac_toe_in_android.view;

import com.example.tic_tac_toe_in_android.R;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class OptionMenuActivity extends Activity implements OnClickListener {
	// SharedPreferences
	// private final String PREFS = "com.example.tic_tac_toe_in_android.view";

	// buttons
	Button bTStart;

	// textViews
	TextView tVrecentScore1;

	// edit Texts
	EditText eTPlayerOneName;
	EditText eTPlayerTwoName;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_option_menu);

		bTStart = (Button) findViewById(R.id.BTStart);
		bTStart.setOnClickListener(this);

		// textViews
		tVrecentScore1 = (TextView) findViewById(R.id.TVrecentScore1);

		// edit texts
		eTPlayerOneName = (EditText) findViewById(R.id.ETplayerOneName);
		eTPlayerTwoName = (EditText) findViewById(R.id.ETplayerTwoName);

	}

	@Override
	protected void onResume() {
		super.onResume();
		loadScores();
	}

	public void onClick(View v) {
		Intent intent;

		if (v == bTStart) {
			intent = new Intent(this, BoardActivity.class);
			if (getPlayerOneName().isEmpty() & getPlayerTwoName().isEmpty()) {
				intent.putExtra("playerOneName", "TYSON");
				intent.putExtra("playerTwoName", "ALI");

			} else if (getPlayerOneName().isEmpty()
					& !getPlayerTwoName().isEmpty()) {

				intent.putExtra("playerOneName", "TYSON");
				intent.putExtra("playerTwoName", getPlayerTwoName());
			} else if (!getPlayerOneName().isEmpty()
					& getPlayerTwoName().isEmpty()) {
				intent.putExtra("playerOneName", getPlayerOneName());
				intent.putExtra("playerTwoName", "ALI");

			} else {
				intent.putExtra("playerOneName", getPlayerOneName());
				intent.putExtra("playerTwoName", getPlayerTwoName());

			}
			startActivity(intent);
		} else {
			System.out.println("ERROR");
		}

	}

	public String getPlayerOneName() {
		return eTPlayerOneName.getText().toString();
	}

	public String getPlayerTwoName() {
		return eTPlayerTwoName.getText().toString();
	}

	public void loadScores() {
		String temp = GameSharedPreferences.load(this);
		tVrecentScore1.setText("" + temp);
	}
}
